package com.rritw.webtools.action.tool;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.util.HtmlUtils;

import com.rritw.webtools.action.IpsAction;
import com.rritw.webtools.util.JDOMUtil;

@Controller
@Scope("prototype")
public class FormatXmlAction extends IpsAction {

    private static final long   serialVersionUID = 9183870837902196807L;
    private static final Logger log              = Logger.getLogger(FormatXmlAction.class);
    private String              xmlContent;

    public String index() {
        super.init();
        return SUCCESS;
    }

    public String create() {
        try {
            super.init();
            xmlContent = JDOMUtil.toXML(JDOMUtil.getDocument(xmlContent));
            xmlContent = HtmlUtils.htmlEscape(xmlContent);
        } catch (Exception e) {
            result = "Format xml exception happened:" + e.getMessage();
            log.error(result, e);
            code = 500;
        }
        return SUCCESS;
    }

    public String getXmlContent() {
        return xmlContent;
    }

    public void setXmlContent(String xmlContent) {
        this.xmlContent = xmlContent;
    }

}
